package com.baby.springboot.consumer;

import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

@Component
@RabbitListener(queuesToDeclare = @Queue("hello"))
public class HelloQueueConsumer {

    /**
     * 简单模式
     * @param msg
     */
//    @RabbitHandler
//    public void consumer(String msg){
//        SimpleDateFormat formatter = new SimpleDateFormat("yyyy年-MM月dd日-HH时mm分ss秒");
//        System.out.println("消息本身是："+msg+" "+formatter.format(new Date(System.currentTimeMillis())));
//    }

    /**
     * 和上面相等
     * @param msg
     */
    @RabbitListener(queuesToDeclare = @Queue("mirror_hello"))
    public void consume(String msg){
        System.out.println("消费消息：" + msg + " " + System.currentTimeMillis());
    }


}
